use std::i32::MAX;

// 330 Patching array
fn min_patches(nums: Vec<i32>, n: i32) -> i32 {
    let mut index: usize = 0;
    let mut bound: i64= 1;
    let mut patch = 0;
    while bound <= n as i64 {
        if index < nums.len() && nums[index] as i64 <= bound {
            bound += nums[index] as i64;
            index += 1;
        } else {
            bound *= 2;
            patch += 1;
        }
    }
    patch
}

#[test]
fn test_min_patches() {
    println!("{}", min_patches(vec![2,3], 6));
    // println!("{}", min_patches(vec![1,5,10], 20));
}

fn increasing_triplet(nums: Vec<i32>) -> bool {
    let (mut a, mut b) = (MAX, MAX);
    for v in nums.iter() {
        if *v <= a {  // 注意这里要是小于等于，因为是全序关系 nums[i] < nums[j] < nums[k]
            a = *v;
        } else if *v <= b {
            b = *v; // 第二小的元素
        } else {
            return true;
        }
    }
    false
}

#[test]
fn test_increasing_triplet() {
    println!("{}", increasing_triplet(vec![1,1,-2,6]));
}